<template>
	<!-- 历史记账页 -->
	<view class="wrap back" style="padding-top: 20rpx;">
		<navigator
			:url="'../person/details?id=' + (item.id + '-' + item.col + '-' + item.user_type + '-' + item.month)"
			class="item flex flex-pack-justify flex-align-center Jbetween Acenter"
			v-for="(item, index) in billListData"
			:key="item.index"
		>
			<view class="flex flex-align-center">
				<image src="../static/jizhang.png"></image>
				<view class="flex-1">
					<text class="title f30">{{ item.month }}月支出</text>
					<text class="c999 f24" style="margin-top: 20rpx; margin-bottom: 20rpx">{{ item.name }}</text>
					<text class="c999 f24">{{ item.createtime || '暂无时间' }}</text>
				</view>
			</view>
			<text class="money f34">¥{{ item.totel ? item.totel : item.turnover }}</text>
		</navigator>
	</view>
</template>

<script>
import util from '../../../utils/util.js';
export default {
	data() {
		return {
		    // 记账列表数据
			billListData: [],
			//  类型人
			user_type: '',
			// 用户id
			id: ''
		};
	},
	onLoad(options) {
		console.log('获取传递过来的用户信息',options)
		if (options.id && options.user_type) {
			this.id=options.id,
			this.user_type=options.user_type
		} // 获取记账列表数据
		this.getBillListData();
	},
	onReachBottom() {
		this.loadStatus = 'loading';
		// 模拟数据加载
		setTimeout(() => {
			// this.addRandomData();
			this.loadStatus = 'loadmore';
		}, 1000);
	},
	methods: {
		// 获取记账列表数据
		getBillListData: function () {
			uni.showToast({
				title: '加载中...',
				icon: 'loading',
				duration: 1000
			});
			var that = this;
			uni.request({
				method: 'POST',
				url: 'https://jizhang.xqyu.cn/index.php/api/index/get_bill',
				dataType: 'json',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				data: {
					id: that.id,
					user_type: that.user_type
				},
				success: function (res) {
					// 数据加载完成，隐藏弹窗
					uni.hideLoading();

					if (res.data.code == 1) {
						var result = res.data.data; // 时间格式化

						result.forEach((item, index) => {
							if (item.createtime !== null) {
								let time = util.timestampToTime(item.createtime);
								var creatTimeObj = result[index];
								creatTimeObj.createtime = time;
							}
						});
						that.billListData= res.data.data
					}
				}
			});
		}
	}
};
</script>

<style>
/* page不能写带scope的style标签中，否则无效 */
page {
	background-color: rgb(240, 240, 240);
}
</style>

<style lang="scss" scoped>
.item {
    border-bottom: 1px #e5e5e5 solid;
    padding-bottom: 30rpx;
    margin-top: 30rpx;
    margin-left: 30rpx;
    margin-right: 30rpx;
}
.item image {
    width: 58rpx;
    height: 58rpx;
    margin-right: 20rpx;
}
text {
    display: block;
}
.money {
    font-weight: bold;
}
.title {
    font-weight: bold;
}

.more {
    margin-top: 100rpx;
}
</style>
